#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
int a[MAXN];
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int T;
    scanf("%d",&T);
    while(T--){
        int n,ans = 0;
        scanf("%d",&n);
        for(int i = 0; i < n; ++i)scanf("%d",&a[i]);
        for(int s = 0; s < (1<<n); ++s){
            int res = 0,r = 0,b = 0;
            for(int i = 0; i < n; ++i){
                if((s>>i)&1){
                    if(a[i]==b)res+=b;
                    b = a[i];
                }else{
                    if(a[i]==r)res+=r;
                    r = a[i];
                }
            }
            ans = max(ans,res);
        }
        printf("%d\n",ans);
    }
	return 0;
}
